{extend name="../public/header" /}
{block name="body"}
<body>
{include file="../public/top" uname="$roleInfo.uname" lv="$roleInfo.ulv" ls="$roleInfo.uyxb" jp="$roleInfo.uczb" /}
<div class="subject main">
    <div class="layui-row">
        <div class="content">
            <div class="current">
                <span class="position">{$roleInfo.map.mname}</span>
                <span class="state">{if $roleInfo.map.ispvp==0}[安全区]{else/}[PVP]{/if}</span>
                <span class="info ajax-goto" data-url="{:url('home/index')}">返回</span>
            </div>
            <div class="refine">
                <div class="friends">
                    <div class="layui-col-md12" style="margin-bottom: 10px;">
                        <div class="layui-card" style="padding: 10px 0;">
                            <div class="layui-card-body">
                                <textarea id="msg" name="msg" placeholder="请输入内容" class="layui-textarea"></textarea>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md12" style="margin-bottom: 10px;">
                        <div class="layui-panel" style="padding: 10px;">
                            <button type="button" class="layui-btn layui-btn-primary layui-btn-xs ajax-act">发送</button>
                        </div>
                    </div>
                    <div class="layui-col-md12">
                        <div class="layui-panel">
							<div class="news" style="max-height:250px;">
								<ul class="flow-default" id="LAY_demo"></ul>
							</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
{/block}
{block name="script"}
<script>
    layui.use(['jquery', 'form', 'layajax', 'upload', 'flow', 'element'], function () {
        var $ = layui.jquery
            , layajax = layui.layajax
            , upload = layui.upload
            , element = layui.element
            , flow = layui.flow
            , form = layui.form;

        flow.load({
            elem: '#LAY_demo' //流加载容器
            , done: function (page, next) { //执行下一页的回调
                var lis = [];

                var map = {};
                map['page'] = page;
                $.post("{:url('home/getMessage')}", map, function (res) {
                    if (res.code == undefined) {
                        res = JSON.parse(res);
                    }
                    if (res.code == 1) {
                        layui.each(res.data.list, function (index, item) {
                            lis.push('<li>' + item.name + ':' + item.msg + '</li>');
                        });

                        //执行下一页渲染，第二参数为：满足“加载更多”的条件，即后面仍有分页
                        //pages为Ajax返回的总页数，只有当前页小于总页数的情况下，才会继续出现加载更多
                        next(lis.join(''), page < res.data.pages);
                    }
                });
            }
        });
		
		$('.ajax-act').on('click', function () {
            var obj = $(this);
            var msg = $('#msg').val();

            var url = '{:url("chatAct")}';
            console.log('url', url);

            var map = {};
            map['msg'] = msg;

            if(msg==''){
                layer.msg('内容不能为空',{time:1000});
                return false;
            }

            $.post(url, map, function (res) {
                if (res.code == undefined) {
                    console.log('res为json字符串', res);
                    res = JSON.parse(res);
                } else {
                    console.log('res为json对象', res);
                }
                if (res.code == 1) {
                    layer.msg(res.msg,{time:1000}, function(index){
                        location.reload();
                    });
                } else {
                    layer.msg(res.msg);
                }
            });
        });

        form.render();
    });
</script>
{/block}